import re

def convert_case_data(array_str_dic):
    ret_dic = {}
    for k, v in array_str_dic.items():
        if k in ['GroupID']:
            continue
        if k.endswith("(Array)"):
            k = remove_end_substr(k, "Array")
            if type(v)!=list:
                v_list = eval(v)
            else:
                v_list = v

            v_list_ret = []
            #继续转换v_temp,因为其中也可能有嵌套的数组，等其他格式数据
            for i in v_list:
                convt_ret = convert_case_data(i)
                v_list_ret.append(convt_ret)

            ret_dic[k] = v_list_ret
        elif k.endswith("(Object)"):
            k = remove_end_substr(k, "Object")
            # k = k.strip("(Object)")
            if type(v)!=dict:
                v_dict = eval(v)
            else:
                v_dict = v

            # 继续转换v_dict,因为其中也可能有嵌套的Object，等其他格式数据
            convt_ret = convert_case_data(v_dict)
            ret_dic[k] = convt_ret
        elif k.endswith("(Number)"):
            k = remove_end_substr(k, "Number")
            v = str(v)#因为从blade传递过来的数据有的不是字符串类型，所以直接转为字符串类型
            if is_number(v) and "." in v:
                v = float(v)
            elif is_number(v):
                v = int(v)
            else:
                raise Exception("此处只接受数值类型数，{}为非数字".format(v))
            ret_dic[k] = v
        elif k.endswith("(ArrayNoKey)"):
            k = remove_end_substr(k, "ArrayNoKey")
            if type(v)!=list:
                v = eval(v)
            ret_dic[k] = v
        else:
            ret_dic[k] = v

    return ret_dic

def remove_end_substr(s, remove_str):
    return re.sub("\("+remove_str+"\)$", "", s)

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False